import {repoList, tagList, downloadLocal} from './utils/git';
import ora from 'ora'; // 进度条
import inquirer from 'inquirer'; // 交互命令

const install = async () => {
    let loading = ora('fetching template ......');
    loading.start();
    let list = await repoList();
    console.log('list---', list);
    loading.succeed();
    list = list.map(({name}) => name);
    let answer = await inquirer.prompt([{
        type: 'list',
        name: 'project',
        choices: list,
        questions: 'please choice template'
    }]);
    let project = answer.project;
    loading = ora('fetching tag ......');
    loading.start();
    list = await tagList(project);
    loading.succeed();
    list = list.map(({name}) => name);
    answer = await inquirer.prompt([{
        type: 'list',
        name: 'tag',
        choices: list,
        questions: 'pleace choice template'
    }]);
    let tag = answer.tag;
    loading = ora('downloading project ......');
    loading.start();
    await downloadLocal(project, tag);
    loading.succeed();
};
export default install;